<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.3.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"example.com","root":"/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.json"};
  </script>

  <meta name="description" content="搬砖 嵌入式">
<meta property="og:type" content="website">
<meta property="og:title" content="学无止境">
<meta property="og:url" content="http://example.com/page/8/index.html">
<meta property="og:site_name" content="学无止境">
<meta property="og:description" content="搬砖 嵌入式">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="xudonglei">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://example.com/page/8/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : true,
    isPost : false,
    lang   : 'zh-CN'
  };
</script>

  <title>学无止境</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">学无止境</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">Do not bb, show me the example</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content index posts-expand">
            
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2023/09/09/CAN%E6%80%BB%E7%BA%BF%E7%BB%93%E6%9E%84%E4%B8%8E%E4%BC%A0%E8%BE%93%E5%8D%8F%E8%AE%AE/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2023/09/09/CAN%E6%80%BB%E7%BA%BF%E7%BB%93%E6%9E%84%E4%B8%8E%E4%BC%A0%E8%BE%93%E5%8D%8F%E8%AE%AE/" class="post-title-link" itemprop="url">CAN总线结构与传输协议</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-09-09 13:35:57" itemprop="dateCreated datePublished" datetime="2023-09-09T13:35:57+08:00">2023-09-09</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">嵌入式</span></a>
                </span>
            </span>

          
            <span id="/2023/09/09/CAN%E6%80%BB%E7%BA%BF%E7%BB%93%E6%9E%84%E4%B8%8E%E4%BC%A0%E8%BE%93%E5%8D%8F%E8%AE%AE/" class="post-meta-item leancloud_visitors" data-flag-title="CAN总线结构与传输协议" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/09/09/CAN%E6%80%BB%E7%BA%BF%E7%BB%93%E6%9E%84%E4%B8%8E%E4%BC%A0%E8%BE%93%E5%8D%8F%E8%AE%AE/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/09/09/CAN%E6%80%BB%E7%BA%BF%E7%BB%93%E6%9E%84%E4%B8%8E%E4%BC%A0%E8%BE%93%E5%8D%8F%E8%AE%AE/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        原文地址：<a target="_blank" rel="noopener" href="https://www.bilibili.com/video/BV1pc411c7BB/?spm_id_from=333.788&amp;vd_source=2ef3411e1c045a25cc2351abaa2c3ce8">https://www.bilibili.com/video/BV1pc411c7BB/?spm_id_from=333.788&amp;vd_source=2ef3411e1c045a25cc2351abaa2c3ce8</a></p>
<h3 id="1-can总线结构"><a href="#1-can总线结构" class="headerlink" title="1.can总线结构"></a>1.can总线结构</h3><p>​        can总线网络的结构有闭环和开环两种形式。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202309091337327.png" style="zoom:67%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202309091338305.png" style="zoom:47%;">

<p>​        两种结构的CAN网络信号线的典型电压值：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202309091340455.png" style="zoom:56%;">

<h3 id="2-CAN总线传输协议"><a href="#2-CAN总线传输协议" class="headerlink" title="2.CAN总线传输协议"></a>2.CAN总线传输协议</h3><h4 id="2-1位时序和波特率"><a href="#2-1位时序和波特率" class="headerlink" title="2.1位时序和波特率"></a>2.1位时序和波特率</h4><p>​        CAN总线上的节点没有主从之分，同一时刻只有一个节点可以发送数据。CAN总线上的节点是没有地址概念的。数据是以帧为单位传输，帧又分为数据帧，遥控帧等多种。每个帧有一个标识符，每个节点都接收数据，但是可以对接收的帧根据标识符进行过滤。</p>
<p>​        CAN总线没有用于同步的时钟信号，所以需要规定can总线的波特率。</p>
<p>​        下面介绍一个概念：位时序。它是指一个节点采集can总线上一个位数据的时序。通过位时序的控制，can总线可以进行位同步，以吸收节点时钟差异产生的波特率误差，保证接收数据的准确性。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202309091353659.png" style="zoom:67%;">

<p>​        can总线的波特率就由标称位时间来决定，一个标称位时间是（1+m+n）<em>tq，波特率就是1/[（1+m+n）</em>tq]</p>
<h4 id="2-2-帧的总类"><a href="#2-2-帧的总类" class="headerlink" title="2.2 帧的总类"></a>2.2 帧的总类</h4><p>​        CAN网络通信是通过5种类型的帧（frame）进行的，这5种帧及其作用如下表所示：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202309091359786.png" style="zoom:80%;">

<p>​        其中数据帧和遥控帧有ID，也就是标识符，并且有标准格式和扩展格式两种。标准格式的ID是11位，扩展格式的ID是29位。</p>
<h4 id="2-3-标准格式数据帧和遥控帧"><a href="#2-3-标准格式数据帧和遥控帧" class="headerlink" title="2.3 标准格式数据帧和遥控帧"></a>2.3 标准格式数据帧和遥控帧</h4><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202309092134216.png" style="zoom:67%;">

<p>​        数据帧可以分为以下几段，首先是帧起始SOF，它是显性电平；接下来的12位是仲裁段，仲裁段包括11位的ID和一个RTR位，多个节点竞争总线发送数据时，根据仲裁段的数据决定哪个节点优先占用总线，<strong>哪个ID先出现显性电平(逻辑0)，哪个节点就占用总线，所以ID数值越小优先级越高</strong>。</p>
<p>​        如果两个节点发送的数据帧ID相同，再根据仲裁段最后的RTR（远程传输请求的英文缩写）位来裁决，RTR位用于区分数据帧和遥控帧，数据帧优先级高于遥控帧。</p>
<p>​        IDE用于表示帧是标准格式还是扩展格式，标准格式的IDE值为0，扩展格式IDE值为1。</p>
<p>​        RB0是保留位，默认为0。</p>
<p>​        DLC表示数据长度编码，它的数值是0到8（数据帧）。遥控帧的DLC编码数值总是0，因为遥控帧不传递数据。</p>
<p>​        CRC共有16位，前15位是CRC编码，后一位总是隐性电平。</p>
<p>​        接下来是ACK段，包含一个ACK位和一个ACK段界定符。发送节点发送的ACK段是隐性电平，接收节点接收的ACK是显性电平。</p>
<p>​        随后还有7位的EOF（帧结束），由7个隐性位表示。</p>
<p>​        数据帧或遥控帧结束后，后面一般是帧间空间或过载帧，用于分隔开数据帧和遥控帧。</p>
<h4 id="2-4扩展格式数据帧和遥控帧"><a href="#2-4扩展格式数据帧和遥控帧" class="headerlink" title="2.4扩展格式数据帧和遥控帧"></a>2.4扩展格式数据帧和遥控帧</h4><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202309092202638.png" style="zoom:70%;">

<p>​        其中SRR用于替代标准格式中的RTR位，SRR位总是隐性电平，相当于占位符，真正的RTR位在仲裁段的最后一位。</p>
<p>​        RB1和RB0是保留位。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2023/09/07/PWM%E5%92%8CSPWM%E7%9A%84%E5%8C%BA%E5%88%AB/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2023/09/07/PWM%E5%92%8CSPWM%E7%9A%84%E5%8C%BA%E5%88%AB/" class="post-title-link" itemprop="url">PWM和SPWM的区别</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-09-07 21:28:16" itemprop="dateCreated datePublished" datetime="2023-09-07T21:28:16+08:00">2023-09-07</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E7%94%B5%E6%9C%BA/" itemprop="url" rel="index"><span itemprop="name">电机</span></a>
                </span>
            </span>

          
            <span id="/2023/09/07/PWM%E5%92%8CSPWM%E7%9A%84%E5%8C%BA%E5%88%AB/" class="post-meta-item leancloud_visitors" data-flag-title="PWM和SPWM的区别" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/09/07/PWM%E5%92%8CSPWM%E7%9A%84%E5%8C%BA%E5%88%AB/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/09/07/PWM%E5%92%8CSPWM%E7%9A%84%E5%8C%BA%E5%88%AB/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        参考文章链接：<a target="_blank" rel="noopener" href="https://blog.csdn.net/qq_46169301/article/details/120146596">https://blog.csdn.net/qq_46169301/article/details/120146596</a></p>
<p>​                                    <a target="_blank" rel="noopener" href="https://www.woiwrj.com/uncategorized/39708/">https://www.woiwrj.com/uncategorized/39708/</a></p>
<p>​        PWM(Pulse Width Modulation) 简称脉冲宽度调制，是利用微处理器的数字信号输出来对模拟电路进行控制的一种技术。而且PWM的应用可以说是非常的广泛，我们可以用来控制电机的速度，产品上常用的呼吸灯的效果以及在通信的调制等领域都可以看到PWM的应用。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202309072130554.png" style="zoom:67%;">

<p>​        SPWM(Sinusoidal PWM)全称是正弦脉冲宽度调制，是一种 广泛应用于电机驱动，逆变电源等领域的调制技术。SPWM波是一种按正弦规律变化的一种PWM波形，是PWM的一种延伸，是一种可以等效成正弦波效果的PWM技术。【网上另一种解释是这样的： 所谓SPWM，<strong>就是在PWM的基础上改变了调制脉冲方式，脉冲宽度时间占空比按正弦规律排列，这样输出波形经过适当的滤波可以做到正弦波输出</strong>。它广泛地用于直流交流逆变器等，比如高级一些的UPS就是一个例子。三相SPWM是使用SPWM模拟市电的三相输出，在变频器领域被广泛的采用。】</p>
<p>​        如果要平稳地驱动三相电机转动，我们就需要生成三个相位相差120度的正弦波，然后形成圆形旋转磁场，最终带动电机转动。但是我们最终的控制对象是MOS管的开通和关断，只有电压最大值和0值两个状态啊，怎么去生成连续变化的正弦波呢？用前面提到的PWM技术就可以做到，所谓SPWM就是这么干的，如下图：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202309072137623.png" style="zoom:80%;">

<p>​        大家观察一下上图的波形，我们用上面坐标系中的正弦波和三角波的交点投影到下面的坐标轴，以此确定PWM的占空比变化规律，这样合成的PWM波，经过低通滤波器之后，其实就等效为了一个正弦波！所以SPWM就是在PWM的基础上用正弦波来调制合成的具有正弦波规律变化的方波。</p>
<p>​        我们把局部展开图放大如下所示:</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202309072138970.png" style="zoom:80%;">

<p>​        通过局部放大图可以知道，锯齿波和调制正弦波的交点为A和B，因此A点所需时间为T1，B点所需时间为T2，所以在该周期内，PWM所需要的脉冲时间宽度为Ton。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2023/09/06/%E6%9D%B0%E7%90%86%E5%A4%8D%E4%BD%8D/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2023/09/06/%E6%9D%B0%E7%90%86%E5%A4%8D%E4%BD%8D/" class="post-title-link" itemprop="url">杰理复位</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-09-06 14:44:01" itemprop="dateCreated datePublished" datetime="2023-09-06T14:44:01+08:00">2023-09-06</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">嵌入式</span></a>
                </span>
            </span>

          
            <span id="/2023/09/06/%E6%9D%B0%E7%90%86%E5%A4%8D%E4%BD%8D/" class="post-meta-item leancloud_visitors" data-flag-title="杰理复位" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/09/06/%E6%9D%B0%E7%90%86%E5%A4%8D%E4%BD%8D/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/09/06/%E6%9D%B0%E7%90%86%E5%A4%8D%E4%BD%8D/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        固件不正常重启，log如下：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信图片_20230512163309.png" style="zoom:67%;">

<p>​        看下断言，是什么报错：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20230512163504.png" style="zoom:67%;">

<p>​        报错显示的log如下：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20230512163720.png" style="zoom:67%;">

<p>​        报错的log可以参考下面这个链接中的资料：<a target="_blank" rel="noopener" href="https://doc.zh-jieli.com/AC63/zh-cn/release_v2.2.1/getting_started/code_debug/printf_debug.html#mmu-err-case">https://doc.zh-jieli.com/AC63/zh-cn/release_v2.2.1/getting_started/code_debug/printf_debug.html#mmu-err-case</a></p>
<p><strong>如何用代码判断系统是什么原因造成的重启</strong></p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">u8 p3_reset_src = P33_CON_GET(P3_RST_SRC);</span><br><span class="line">   u8 r3_reset_src = P33_CON_GET(R3_RST_SRC);</span><br><span class="line">   log_info(<span class="string">&quot;%s[P3:0x%x R3:0x%x]&quot;</span>, __func__, p3_reset_src, r3_reset_src);</span><br><span class="line">   <span class="comment">//p3_reset_src:</span></span><br><span class="line">   <span class="comment">//0x01:VDDIO_POR</span></span><br><span class="line">   <span class="comment">//0x02:VDDIO_LVD</span></span><br><span class="line">   <span class="comment">//0x04:WDT</span></span><br><span class="line">   <span class="comment">//0x10:PPINR</span></span><br><span class="line">   <span class="comment">//0x40:SOFT_RESET</span></span><br></pre></td></tr></table></figure>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信图片_20230906111820.png" style="zoom:80%;">

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2023/09/03/%E7%81%AF%E5%93%A5%E6%95%99%E7%A8%8B%E4%B9%8B%E5%BC%80%E7%8E%AF%E9%80%9F%E5%BA%A6%E4%BB%A3%E7%A0%81%E7%BC%96%E7%A8%8B%E5%92%8C%E7%A1%AC%E4%BB%B6%E8%B0%83%E8%AF%95/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2023/09/03/%E7%81%AF%E5%93%A5%E6%95%99%E7%A8%8B%E4%B9%8B%E5%BC%80%E7%8E%AF%E9%80%9F%E5%BA%A6%E4%BB%A3%E7%A0%81%E7%BC%96%E7%A8%8B%E5%92%8C%E7%A1%AC%E4%BB%B6%E8%B0%83%E8%AF%95/" class="post-title-link" itemprop="url">灯哥教程之开环速度代码编程和硬件调试</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-09-03 21:11:15" itemprop="dateCreated datePublished" datetime="2023-09-03T21:11:15+08:00">2023-09-03</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E7%94%B5%E6%9C%BA/" itemprop="url" rel="index"><span itemprop="name">电机</span></a>
                </span>
            </span>

          
            <span id="/2023/09/03/%E7%81%AF%E5%93%A5%E6%95%99%E7%A8%8B%E4%B9%8B%E5%BC%80%E7%8E%AF%E9%80%9F%E5%BA%A6%E4%BB%A3%E7%A0%81%E7%BC%96%E7%A8%8B%E5%92%8C%E7%A1%AC%E4%BB%B6%E8%B0%83%E8%AF%95/" class="post-meta-item leancloud_visitors" data-flag-title="灯哥教程之开环速度代码编程和硬件调试" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/09/03/%E7%81%AF%E5%93%A5%E6%95%99%E7%A8%8B%E4%B9%8B%E5%BC%80%E7%8E%AF%E9%80%9F%E5%BA%A6%E4%BB%A3%E7%A0%81%E7%BC%96%E7%A8%8B%E5%92%8C%E7%A1%AC%E4%BB%B6%E8%B0%83%E8%AF%95/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/09/03/%E7%81%AF%E5%93%A5%E6%95%99%E7%A8%8B%E4%B9%8B%E5%BC%80%E7%8E%AF%E9%80%9F%E5%BA%A6%E4%BB%A3%E7%A0%81%E7%BC%96%E7%A8%8B%E5%92%8C%E7%A1%AC%E4%BB%B6%E8%B0%83%E8%AF%95/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        原文链接：<a target="_blank" rel="noopener" href="http://www.dengfoc.com/#/dengfoc/%E7%81%AF%E5%93%A5%E6%89%8B%E6%8A%8A%E6%89%8B%E6%95%99%E4%BD%A0%E5%86%99FOC%E7%AE%97%E6%B3%95/4.2FOC%E5%BC%80%E7%8E%AF%E9%80%9F%E5%BA%A6%E4%BB%A3%E7%A0%81%E7%9A%84%E5%8E%9F%E7%90%86%E6%95%99%E5%AD%A6">http://www.dengfoc.com/#/dengfoc/%E7%81%AF%E5%93%A5%E6%89%8B%E6%8A%8A%E6%89%8B%E6%95%99%E4%BD%A0%E5%86%99FOC%E7%AE%97%E6%B3%95/4.2FOC%E5%BC%80%E7%8E%AF%E9%80%9F%E5%BA%A6%E4%BB%A3%E7%A0%81%E7%9A%84%E5%8E%9F%E7%90%86%E6%95%99%E5%AD%A6</a></p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202309032113291.png" style="zoom:67%;">

<p>​        在开始写代码前，我们先来确定一下我们不同功能块的函数名称。如上图所示：帕克逆变换和克拉克逆变换，我将把它直接写在一个代码函数里，这个代码函数我命名为setPhaseVoltage，setPhaseVoltage会计算出电机控制需求的Ua, Ub, Uc ，并通过setPWM函数传递给电机驱动器硬件，接着，硬件就会产生对应的三相电压波形进行电机的控制。</p>
<p>​        除了setPhaseVoltage函数之外，我们还需要一个velocityOpenloop函数，这个函数主要是根据用户输入的目标电机转速target_velocity计算出在这个速度下的Uq 值和电角度值，进而传递给setPhaseVoltage函数进行下一步的计算。<br>  好了，在明确了各个函数的用途之后，我们就开始一个个来撰写我们的核心函数，我将一个个函数的给大家进行解释，并在最后形成一个完整的FOC开环速度控制代码。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202309032124591.png" style="zoom:80%;">

<p>​        我们先来看看setPhaseVoltage函数，这个函数的作用是，给额定的Uq 和电角度，它就能通过帕克逆变换和克拉克逆变换，计算出<br>Ua,Ub,Uc 值，并最终通过setpwm函数传递给电机硬件。<br>  在上节课，我说过，<strong>电机的输出力矩主要是由Uq 决定的</strong>，简单的应用中我们可以把Ud设置为0，于是今天我们就直接把Ud=0，因此帕克逆变换中我们就可以消去Ud 项，代码式子就因此如红色箭头右边的截图所示。<br>  对于克拉克逆变换，我们首先把左边的这个式子直接的写成这里的代码，但是你可以发现，代码和式子是有区别的，代码中，我们给<br>Ua,Ub,Uc 每项加入了一个：voltage_power_supply/2项，这个是什么呢？这个其实是供电电压/2，比如，如果给板子的供电电压是12V，那么这个voltage_power_supply/2=12/2=6,它的存在主要是将生成的Ua,Ub,Uc 曲线平移到供电电压的中间，因为原始的Ua,Ub,Uc  一个类似正弦曲线的输出形式，会有电压 &lt; 0的部分，避免产生电压&lt; 0部分（实际的电路中我们是没办法生成负电压的），因此我们需要把所有的电压都维持在正的情况，这也是为什么我们要将电压平移。<br>  _normalizeAngle函数：这个函数将电角度限制在0-2PI之间，也就是0-360度之间。<br>  这就是这个函数的全部，有了它，我们就可以在函数中输入我们期望的Uq 和电角度，就可以方便的求出对应的三相Ua,Ub,Uc。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202309032131412.png" style="zoom:80%;">

<p>​        到这里，我们就已经明白了帕克逆变换、克拉克逆变换和驱动器部分setPWM的程序写法。但是，不要忘记我们这节课要写的是开环速度FOC算法，因此我们还需要有一个能够根据用户所需要输入的期望速度，<strong>自动生成Uq 和旋转的电角度的程序代码，这就是上图中绿色框打着问号的Uq 和旋转的电角度生成器。当通过它生成了按照期望速度旋转变化的电角度和Uq 值后，输入给刚刚我们编写的setPhaseVoltage和setPwm函数中，就可以使得电机最终物理旋转。</strong></p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202309032149188.png"></p>
<p>​        这就是我们的Uq和旋转的电角度生成器”代码，具体的解释已经非常完整的写在了解释中！在搞明白Uq 和旋转的电角度生成器”代码的同时，也就是搞懂我们的velocityOpenloop函数的同时，还需要同时搞明白它的电角度求解函数。</p>
<p>​        <strong><u>因为在开环的情况下，你没有编码器，所以实际上这个轴角度（shaft_angle）我们直接通过运算去生成一个不断旋转的轴角度，把它强行的给设定在FOC算法里，就可以让电机转动起来了。</u></strong></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2023/09/03/esp32%20arduino%20PWM%E5%AD%A6%E4%B9%A0/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2023/09/03/esp32%20arduino%20PWM%E5%AD%A6%E4%B9%A0/" class="post-title-link" itemprop="url">esp32 arduino PWM学习</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-09-03 19:39:42" itemprop="dateCreated datePublished" datetime="2023-09-03T19:39:42+08:00">2023-09-03</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">嵌入式</span></a>
                </span>
            </span>

          
            <span id="/2023/09/03/esp32%20arduino%20PWM%E5%AD%A6%E4%B9%A0/" class="post-meta-item leancloud_visitors" data-flag-title="esp32 arduino PWM学习" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/09/03/esp32%20arduino%20PWM%E5%AD%A6%E4%B9%A0/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/09/03/esp32%20arduino%20PWM%E5%AD%A6%E4%B9%A0/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​         原文链接：<a target="_blank" rel="noopener" href="https://www.cnblogs.com/Xin-chen/p/16846123.html">https://www.cnblogs.com/Xin-chen/p/16846123.html</a></p>
<p>​                            <a target="_blank" rel="noopener" href="https://blog.csdn.net/weixin_42880082/article/details/120844924">https://blog.csdn.net/weixin_42880082/article/details/120844924</a></p>
<p>​        LED控制（LEDC）外围设备主要用于控制LED的强度，尽管它也可以用于生成PWM信号用于其他目的。它具有16个通道，可以生成独立的波形，这些波形可以用于驱动RGB LED器件。</p>
<p>​        LEDC通道分为两组，每组8个通道。一组LEDC通道以高速模式运行。此模式在硬件中实现，并提供PWM占空比的自动且无干扰的更改。另一组通道在低速模式下运行，PWM占空比必须由驱动程序在软件中进行更改。每组通道还能够使用不同的时钟源。</p>
<p>​        PWM控制器可以自动逐渐增加或减少占空比，从而允许淡入而不会受到任何处理器干扰。</p>
<h3 id="相关函数"><a href="#相关函数" class="headerlink" title="相关函数"></a>相关函数</h3><p>​        <strong>double ledcSetup(uint8_t chan, double freq, uint8_t bit_num)</strong></p>
<p>​        功能为设置LEDC通道对应的频率和计数复位<br>​        uint8_t chan 表示通道号，取值为0-15 最多可设置16个通道<br>​        double freq 期望设置的频率<br>​        uint8_t bit_num 占空比复位计数，取值为0-20，该值决定后面ledcWrite方法中占空比可写值，如果写值为10 则占空比最大为2^10-1 1024-1 = 1023</p>
<p>​        <strong>void ledcAttachPin(uint8_t pin, uint8_t channel);</strong></p>
<p>​        将通道和I/O口连接<br>​        第一个参数为引脚号，第二个参数为设置的通道</p>
<p>​        <strong>void ledcWrite(uint8_t chan, uint32_t duty)</strong></p>
<p>​        指定的 LEDC 通道的输出占空比</p>
<p>​        第一个参数chan为我们指定的LEDC通道，第二个参数duty表示占空比，其取值范围与ledcSetup()函数的bit_num有关。</p>
<h3 id="实列代码"><a href="#实列代码" class="headerlink" title="实列代码"></a>实列代码</h3><p>​        输出固定占空比：PWM频率为2KHz，分辨率为2的8次幂256，输出占空比为50%</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;Arduino.h&gt;</span></span></span><br><span class="line"><span class="comment">/* 设置led输出引脚号 */</span></span><br><span class="line"><span class="keyword">uint8_t</span> led_pin = <span class="number">2</span>;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">setup</span><span class="params">()</span> </span></span><br><span class="line"><span class="function"></span>&#123;            </span><br><span class="line">  Serial.begin(<span class="number">115200</span>);</span><br><span class="line">  delay(<span class="number">10</span>); </span><br><span class="line"></span><br><span class="line">  <span class="comment">/* 1. 使用ledc通道1，设置频率为2kHz，分辨率为8位 */</span></span><br><span class="line">  <span class="keyword">double</span> f = ledcSetup(<span class="number">1</span>, <span class="number">2000</span>, <span class="number">8</span>);  </span><br><span class="line">  Serial.print(<span class="string">&quot;F=&quot;</span>);Serial.println(f); <span class="comment">/* 打印实际设置的频率*/</span></span><br><span class="line"></span><br><span class="line">  <span class="comment">/* 2. 将LED引脚绑定到ledc通道1 */</span></span><br><span class="line">  ledcAttachPin(led_pin, <span class="number">1</span>);</span><br><span class="line"></span><br><span class="line">  <span class="comment">/* 3. 设置ledc通道占空比为128/256=50% */</span></span><br><span class="line">  ledcWrite(<span class="number">1</span>, <span class="number">128</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">loop</span><span class="params">()</span> </span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  delay(<span class="number">100</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2023/09/02/%E7%BC%96%E5%86%99%E8%87%AA%E5%B7%B1%E7%9A%84Arduino%E5%BA%93/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2023/09/02/%E7%BC%96%E5%86%99%E8%87%AA%E5%B7%B1%E7%9A%84Arduino%E5%BA%93/" class="post-title-link" itemprop="url">编写自己的Arduino库</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-09-02 16:59:31" itemprop="dateCreated datePublished" datetime="2023-09-02T16:59:31+08:00">2023-09-02</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">嵌入式</span></a>
                </span>
            </span>

          
            <span id="/2023/09/02/%E7%BC%96%E5%86%99%E8%87%AA%E5%B7%B1%E7%9A%84Arduino%E5%BA%93/" class="post-meta-item leancloud_visitors" data-flag-title="编写自己的Arduino库" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/09/02/%E7%BC%96%E5%86%99%E8%87%AA%E5%B7%B1%E7%9A%84Arduino%E5%BA%93/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/09/02/%E7%BC%96%E5%86%99%E8%87%AA%E5%B7%B1%E7%9A%84Arduino%E5%BA%93/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​         原文链接：<a target="_blank" rel="noopener" href="https://www.cnblogs.com/lulipro/p/6090407.html">https://www.cnblogs.com/lulipro/p/6090407.html</a></p>
<p>​        一开始写Arduino 的时候很不习惯，没有main函数，因为好多东西都被隐藏了。一直想搞清楚，以便编写自己的库文件。于是研究了一下，下面是一些总结。</p>
<h3 id="一、目录规范"><a href="#一、目录规范" class="headerlink" title="一、目录规范"></a>一、目录规范</h3><p>​        当创建一个空的工程，先按下ctrl+s保存一下。这个时候弹出对话框，命名工程。假如命名为UART，并保存在自己的Arduino工作目录下 。</p>
<p>​        于是IDE会自动帮我们在workspace下创建1个文件夹，并将sketch主文件放在里面，而且主文件和文件夹同名。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202309021710154.png" style="zoom:67%;">

<h3 id="二、主文件代码框架规范"><a href="#二、主文件代码框架规范" class="headerlink" title="二、主文件代码框架规范"></a><strong>二、主文件代码框架规范</strong></h3><p>​        每一个Arduino程序（Sketch）都有1个主文件，后缀为 <strong>.ino</strong> ，它是程序的setup 函数和 loop函数所在的文件。</p>
<p>​        有C/C++开发经验的人看到这个程序框架会愣住：我的main函数去哪里呢？</p>
<p>​        Arduino  为了让更多的人能够使用Arduino平台开发出好玩的东西出来，绞尽脑汁降低门槛，它隐藏了程序的细节，使得开发者将注意力放在实现上。</p>
<p>​        在Arduino IDE的安装目录下可以找到main.cpp这个代码模板文件，main函数就位于此。文件位置：{Arduino安装目录}\hardware\arduino\avr\cores\arduino\main.cpp。</p>
<h3 id="三、项目中使用多文件之无后缀的文件"><a href="#三、项目中使用多文件之无后缀的文件" class="headerlink" title="三、项目中使用多文件之无后缀的文件"></a>三、项目中使用多文件之无后缀的文件</h3><p>​        有时会程序越写越大，越大越乱。多文件管理可以解决这个麻烦。Arduino程序可以有多个源代码文件，但只有 1个 主文件，也就是存放 setup、loop函数的.ino文件。为了使得代码更清晰，我们让主文件用来控制程序的主要逻辑部分，而把具体的细节封装成单个模块，存放在其他的文件中，这样方便管理。</p>
<p>​        使用无后缀的文件（其实是以.ino为后缀的，只是在IDE中不会显示后缀，而在电脑的资源管理器中会显示.ino  ， 以下都称为无后缀）</p>
<p>​        点击下图中标记的按钮，选择第一个选项 【新建标签】，输入文件名即可。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202309021723553.png" style="zoom:80%;">

<p>​        这样我们的工程就有了2个文件了。如下，一个主文件和一个名为LED的文件。这就是最简单的多文件方法。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202309021724066.png" style="zoom:67%;">

<p>​        我不推荐使用这种方法，这是为没有C/C++编程经验的小白准备的，他们不懂函数定义 后还要声明才能使用，不懂得头文件的包含。这些都被Arduino IDE帮他们做了。IDE的具体处理是</p>
<p>​        在编译前期，Arduino IDE会将无后缀的文件 和 主文件合并成为1个文件，效果就像是写在主文件中一样。并在主文件第一行添加  #include “Arduino.h” 。 Arduino.h是 Arduino程序的核心头文件。然后，IDE将扫描合并后文件的函数定义，并对已经定义的函数添加函数的声明。（这个就是为什么即便我们定义的函数不声明也能编译通过的原因了）。但是官方明确说了，这个自动插入函数声明的机制是不完美的！所以我也建议大家养成手动声明函数的习惯。</p>
<h3 id="四、使用传统的-C-C-分离式文件"><a href="#四、使用传统的-C-C-分离式文件" class="headerlink" title="四、使用传统的 C/C++分离式文件"></a>四、<strong>使用传统的 C/C++分离式文件</strong></h3><p>​        这种方式下，对于一个代码模块，我们需要一对文件：源文件和头文件，即： .c  和.h   或者 .cpp 和 .h  。前者是C语言风格，后者是对会使用C++来说的。官方貌似推崇我们使用C++编写Arduino代码，无论是Arduino 的从标准库，还是教程中，都透露出一股强烈的OOP气息。所以我下面使用C++风格来举例子。</p>
<p>​        例如我们想要将UART的打印封装成一个模块。一开始我们需要创建2个文件 ：UART.h   、 UART.cpp</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202309021731215.png" style="zoom:60%;">

<p>​        然后是想清楚我们需要让提供UART控制的哪些操作。发挥你的想象力时候到了。规定操作后，我们先写出头文件，然后写出实现，最后在主文件中使用这个模块。在主文件中使用#include”LED.h”预处理指令包含。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202309022240332.png" style="zoom:80%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202309022241041.png" style="zoom:80%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202309022241113.png" style="zoom:80%;">

<p>​        代码编写好后，点击上传按钮。在下载的时候，需要我们按下esp32板子上的boot按键就下载成功了。</p>
<h3 id="五、让它成为自己的库"><a href="#五、让它成为自己的库" class="headerlink" title="五、让它成为自己的库"></a>五、让它成为自己的库</h3><p>​        如果上面的模块你觉得好用，符合自己的使用习惯，而且经常要用到，那么你可以将它变成你自己的库文件。这样以后就可以直接拿来用啦。Arduino的扩展库都是放在 libraries目录下的。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202309022245233.png" style="zoom:80%;">

<p>​        所以我们需要在这个目录下创建一个文件夹，比如上面的例子是UART控制，于是我创建了 m_UART文件夹（前面加m是为了和官方库区分开，这只是个人的习惯而已）。然后把写好的.cpp 和 .h文件拷贝到里面去，这样就OK了。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202309022248697.png" style="zoom:80%;">

<p>​        这样我们的主文件就变成了下面这样，很简洁干净：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202309022253994.png" style="zoom:80%;">
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2023/06/23/PyQt5%E5%B5%8C%E5%85%A5matplotlib%E7%BB%98%E5%9B%BE/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2023/06/23/PyQt5%E5%B5%8C%E5%85%A5matplotlib%E7%BB%98%E5%9B%BE/" class="post-title-link" itemprop="url">PyQt5嵌入matplotlib绘图</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-06-23 21:01:22" itemprop="dateCreated datePublished" datetime="2023-06-23T21:01:22+08:00">2023-06-23</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/QT/" itemprop="url" rel="index"><span itemprop="name">QT</span></a>
                </span>
            </span>

          
            <span id="/2023/06/23/PyQt5%E5%B5%8C%E5%85%A5matplotlib%E7%BB%98%E5%9B%BE/" class="post-meta-item leancloud_visitors" data-flag-title="PyQt5嵌入matplotlib绘图" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/06/23/PyQt5%E5%B5%8C%E5%85%A5matplotlib%E7%BB%98%E5%9B%BE/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/06/23/PyQt5%E5%B5%8C%E5%85%A5matplotlib%E7%BB%98%E5%9B%BE/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        原文地址：<a target="_blank" rel="noopener" href="https://www.cnblogs.com/kallan/p/5797815.html">https://www.cnblogs.com/kallan/p/5797815.html</a><br>​                            <a target="_blank" rel="noopener" href="https://blog.csdn.net/txh3093/article/details/119955235">https://blog.csdn.net/txh3093/article/details/119955235</a></p>
<h3 id="创建窗体"><a href="#创建窗体" class="headerlink" title="创建窗体"></a>创建窗体</h3><p>​        <strong>widget窗体提升，整合matplotlib的功能</strong></p>
<p>​        matplotlib中的FigureCanvas和GUI中的widget都是Qwidget的子类，matplotlib是无法直接在widget中绘图的，需要在Designer中将widget提升为Qwidget类。选中GUI中的widget右键选择提升窗口部件，选择Qwidget，给提升的类取一个好记的名字。</p>
<p>​        在Qt中添加matplotlib组件窗口需要创建一个新的类mplwidget，在这个类中创建matplotlib的画布，然后在Qt designer中添加一个普通的Widget，然后将这个widget提升为我们所建的类mplwidget。</p>
<p>​        打开Qt Designer后，会有几个基本的窗口，比如自己的窗口“MainWindow“，从“窗口部件盒”拖1个Widget到“MainWindow”，在这个Widget上单击右键，选择【提升为】</p>
<p>​        在“提升的类名称”中输入要创建的自定义的widget类名称，点击【添加】</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20230623210821.png" style="zoom:50%;">

<p>​        选中“提升的类”中新建的那个类，点击【提升】</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20230623211122.png" style="zoom:50%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20230623211227.png" style="zoom:67%;">

<h3 id="自定义Widget类的编写"><a href="#自定义Widget类的编写" class="headerlink" title="自定义Widget类的编写"></a>自定义Widget类的编写</h3><p>mplpiewidget.py文件：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> PyQt5 <span class="keyword">import</span> QtGui, QtCore, QtWidgets</span><br><span class="line"><span class="keyword">from</span> matplotlib.backends.backend_qt5agg <span class="keyword">import</span> FigureCanvasQTAgg <span class="keyword">as</span> FigureCanvas</span><br><span class="line"><span class="keyword">from</span> matplotlib.figure <span class="keyword">import</span> Figure</span><br><span class="line"><span class="keyword">from</span> matplotlib.backends.backend_qt5agg <span class="keyword">import</span> FigureCanvasQTAgg, NavigationToolbar2QT <span class="keyword">as</span> NavigationToolbar</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">MplCanvas</span>(<span class="params">FigureCanvas</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self</span>):</span></span><br><span class="line">        self.fig = Figure()</span><br><span class="line">        self.ax = self.fig.add_subplot(<span class="number">111</span>)</span><br><span class="line">        FigureCanvas.__init__(self, self.fig)</span><br><span class="line">        FigureCanvas.setSizePolicy(self,</span><br><span class="line">                                   QtWidgets.QSizePolicy.Expanding,</span><br><span class="line">                                   QtWidgets.QSizePolicy.Expanding)</span><br><span class="line">        FigureCanvas.updateGeometry(self)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 创建自定义widget类MplPieWidget,继承于QtWidget.QWidget</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">MplPieWidget</span>(<span class="params">QtWidgets.QWidget</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self, parent=<span class="literal">None</span></span>):</span></span><br><span class="line">        QtWidgets.QWidget.__init__(self, parent)</span><br><span class="line">        self.canvas = MplCanvas()</span><br><span class="line">        self.mpl_toolbar = NavigationToolbar(self.canvas, self)  <span class="comment"># 创建工具条</span></span><br><span class="line">        self.vbl = QtWidgets.QVBoxLayout()</span><br><span class="line">        self.vbl.addWidget(self.canvas)</span><br><span class="line">        self.vbl.addWidget(self.mpl_toolbar)</span><br><span class="line">        self.setLayout(self.vbl)</span><br></pre></td></tr></table></figure>
<h3 id="使用的地方"><a href="#使用的地方" class="headerlink" title="使用的地方"></a>使用的地方</h3><p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20230623211838.png"></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2023/06/23/PyQt5%E7%95%8C%E9%9D%A2%E4%B8%8E%E9%80%BB%E8%BE%91%E7%9A%84%E5%88%86%E7%A6%BB/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2023/06/23/PyQt5%E7%95%8C%E9%9D%A2%E4%B8%8E%E9%80%BB%E8%BE%91%E7%9A%84%E5%88%86%E7%A6%BB/" class="post-title-link" itemprop="url">PyQt5界面与逻辑的分离</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-06-23 15:35:26" itemprop="dateCreated datePublished" datetime="2023-06-23T15:35:26+08:00">2023-06-23</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/QT/" itemprop="url" rel="index"><span itemprop="name">QT</span></a>
                </span>
            </span>

          
            <span id="/2023/06/23/PyQt5%E7%95%8C%E9%9D%A2%E4%B8%8E%E9%80%BB%E8%BE%91%E7%9A%84%E5%88%86%E7%A6%BB/" class="post-meta-item leancloud_visitors" data-flag-title="PyQt5界面与逻辑的分离" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/06/23/PyQt5%E7%95%8C%E9%9D%A2%E4%B8%8E%E9%80%BB%E8%BE%91%E7%9A%84%E5%88%86%E7%A6%BB/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/06/23/PyQt5%E7%95%8C%E9%9D%A2%E4%B8%8E%E9%80%BB%E8%BE%91%E7%9A%84%E5%88%86%E7%A6%BB/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        原文地址：<a target="_blank" rel="noopener" href="https://blog.csdn.net/qq_41116319/article/details/125184046">https://blog.csdn.net/qq_41116319/article/details/125184046</a></p>
<h3 id="一、问题描述"><a href="#一、问题描述" class="headerlink" title="一、问题描述"></a>一、问题描述</h3><p>​        当我们用QtDesigner制作完一个.ui界面后，转化成.py文件。之后又对此界面不太满意，想要重新修改完善界面，如果重新修改界面，对应的.py文件也会发生变化，除了自动生成的界面代码，我们还写入了其他逻辑功能程序代码，所以我们除了重新将完善后的.ui文件转化为.py文件外，也还要将自己的逻辑功能代码写进程序。所以工作量会很大。</p>
<h3 id="二、问题思路"><a href="#二、问题思路" class="headerlink" title="二、问题思路"></a>二、问题思路</h3><p>​        将界面文件与自己编写的逻辑程序代码分开，这样当我们修改界面后，只需生成对应的.py文件（界面文件）即可，自己编写的逻辑程序代码也不用跟着重新写进程序了，因为此时界面文件与自己的逻辑功能代码（逻辑文件）是相互独立的，不会受到界面文件变化的影响。即这就是所谓的界面与逻辑的分离。所以需要新建一个.py文件（逻辑文件）来调用界面文件，这个新建的.py文件也就是逻辑文件。</p>
<h3 id="三、示例"><a href="#三、示例" class="headerlink" title="三、示例"></a>三、示例</h3><p>​        新建了一个untitled.ui文件，然后转化成py文件，如下图所示：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20230623153953.png" style="zoom:67%;">

<p>​        我们需要新建一个.py文件（逻辑文件）来调用untitled.py界面文件。将逻辑文件命名为call_untitled.py。添加逻辑功能代码如下：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20230623154320.png" style="zoom:67%;">

<p>​        最后在main.py中调用这个call_untitled文件：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20230623154453.png" style="zoom:67%;">
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2023/05/27/%E7%81%AF%E5%93%A5%E6%95%99%E7%A8%8B%E4%B9%8B%E6%92%B0%E5%86%99%E5%BC%80%E7%8E%AF%E9%80%9F%E5%BA%A6%E4%BB%A3%E7%A0%81%E7%9A%84%E5%89%8D%E7%BD%AE%E7%9F%A5%E8%AF%86/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2023/05/27/%E7%81%AF%E5%93%A5%E6%95%99%E7%A8%8B%E4%B9%8B%E6%92%B0%E5%86%99%E5%BC%80%E7%8E%AF%E9%80%9F%E5%BA%A6%E4%BB%A3%E7%A0%81%E7%9A%84%E5%89%8D%E7%BD%AE%E7%9F%A5%E8%AF%86/" class="post-title-link" itemprop="url">灯哥教程之撰写开环速度代码的前置知识</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-05-27 21:55:32" itemprop="dateCreated datePublished" datetime="2023-05-27T21:55:32+08:00">2023-05-27</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E7%94%B5%E6%9C%BA/" itemprop="url" rel="index"><span itemprop="name">电机</span></a>
                </span>
            </span>

          
            <span id="/2023/05/27/%E7%81%AF%E5%93%A5%E6%95%99%E7%A8%8B%E4%B9%8B%E6%92%B0%E5%86%99%E5%BC%80%E7%8E%AF%E9%80%9F%E5%BA%A6%E4%BB%A3%E7%A0%81%E7%9A%84%E5%89%8D%E7%BD%AE%E7%9F%A5%E8%AF%86/" class="post-meta-item leancloud_visitors" data-flag-title="灯哥教程之撰写开环速度代码的前置知识" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/05/27/%E7%81%AF%E5%93%A5%E6%95%99%E7%A8%8B%E4%B9%8B%E6%92%B0%E5%86%99%E5%BC%80%E7%8E%AF%E9%80%9F%E5%BA%A6%E4%BB%A3%E7%A0%81%E7%9A%84%E5%89%8D%E7%BD%AE%E7%9F%A5%E8%AF%86/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/05/27/%E7%81%AF%E5%93%A5%E6%95%99%E7%A8%8B%E4%B9%8B%E6%92%B0%E5%86%99%E5%BC%80%E7%8E%AF%E9%80%9F%E5%BA%A6%E4%BB%A3%E7%A0%81%E7%9A%84%E5%89%8D%E7%BD%AE%E7%9F%A5%E8%AF%86/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        原文链接：<a target="_blank" rel="noopener" href="https://www.bilibili.com/video/BV1Pc411s7mP/?spm_id_from=333.788&amp;vd_source=2ef3411e1c045a25cc2351abaa2c3ce8">https://www.bilibili.com/video/BV1Pc411s7mP/?spm_id_from=333.788&amp;vd_source=2ef3411e1c045a25cc2351abaa2c3ce8</a></p>
<p>​        <a target="_blank" rel="noopener" href="http://www.dengfoc.com/#/dengfoc/%E7%81%AF%E5%93%A5%E6%89%8B%E6%8A%8A%E6%89%8B%E6%95%99%E4%BD%A0%E5%86%99FOC%E7%AE%97%E6%B3%95/4.2FOC%E5%BC%80%E7%8E%AF%E9%80%9F%E5%BA%A6%E4%BB%A3%E7%A0%81%E7%9A%84%E5%8E%9F%E7%90%86%E6%95%99%E5%AD%A6">http://www.dengfoc.com/#/dengfoc/%E7%81%AF%E5%93%A5%E6%89%8B%E6%8A%8A%E6%89%8B%E6%95%99%E4%BD%A0%E5%86%99FOC%E7%AE%97%E6%B3%95/4.2FOC%E5%BC%80%E7%8E%AF%E9%80%9F%E5%BA%A6%E4%BB%A3%E7%A0%81%E7%9A%84%E5%8E%9F%E7%90%86%E6%95%99%E5%AD%A6</a></p>
<h3 id="三相电压矢量"><a href="#三相电压矢量" class="headerlink" title="三相电压矢量"></a>三相电压矢量</h3><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305272101156.png" style="zoom:60%;">

<p>​        而今天，在开始撰写我们的代码之前，我们对算法的理解需要更进一步。根据我们的第二，第三，第四节课，我们所有的推导其实都是根据电流矢量，也就是最左边这幅图进行的。那么，如果把这个每相的电流矢量都乘上其相电阻R（相电阻就是每相线圈所带的电阻），那会发生什么情况呢？没错，根据欧姆定律，它就会变成每相的电压矢量！如上边这幅图所示，你可以看到在这幅图中，存在Ua,Ub,Uc，他们都是直接由左下角的图的每个相位乘上相电阻R得来的。<br>  而无刷电机的电流矢量，和电压矢量其实没有任何的区别，只是他们的幅值不同！想象一下，最上面这幅黑色的图的三个相位的电流波形曲线，如果都乘上一个相电阻R，那么他们会变成电压波形曲线，它和电流波形曲线的不同只是因为乘上电阻R后导致的幅值不同！</p>
<h3 id="整个FOC算法数学过程总结"><a href="#整个FOC算法数学过程总结" class="headerlink" title="整个FOC算法数学过程总结"></a>整个FOC算法数学过程总结</h3><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305272109423.png" style="zoom:67%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305272118487.png" style="zoom:80%;">

<h3 id="电角度和机械角度的关系"><a href="#电角度和机械角度的关系" class="headerlink" title="电角度和机械角度的关系"></a>电角度和机械角度的关系</h3><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305272145692.png" style="zoom:80%;">

<p>​        还记得上图最左边的这个图吗？这个就是我们上节课上课用的，讲解无刷电机的图。而上图右边的图就是它的另外一种表现形式，这是一个极对数为1的电机，它有两个磁极N和S，除2就是极对数，也就是1<br>  可以看到，假设我们单独只看U相，那么假设我们把电动机看成是一个发电机，那么转子磁极N在磁场中转一圈，切割磁感线，再回到初始位置。所发的电的就是一个发电周期，拥有正半轴和负半轴的部分。</p>
<p>​        那么，现在我们进行以下扩展，把电机扩展为如下图最右边的图所示的有四个磁极的电机，此时这个电机的极对数为4/2=2，那么，假设再把这个电机看成是发电机，旋转一圈，会发生什么呢？显然，<strong>如果还是只关注U相的话，N级会经过U相两次，因此电机转一圈，会有两个发电周期</strong>。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305272150208.png" style="zoom:80%;">

<p>​        同样的现象会出现在极对数更多的电机之中，如我们之前用DengFOC驱动的大航模电机5212，极对数为11,我们可以来看看它的发电周期是多少，我们把电机接上示波器，用手转示波器一圈，如下图所示。</p>
<p>     我们可以看到，总共有11个波锋出现，代表有11个发电周期，恰好等于我们的极对数。而这个现象也正揭示了为什么电角度=机械角度x极对数，那是因为，如果只是刚刚的一级对电机，那么的机械角度转一圈，相位的一个周期是能够和机械角度一一对应的，此时电角度=机械角度；但是，如果是多级电机，那么机械角度转一圈，相位的周期可能是很多个。比如，当我们是刚刚图上的2极对电机时，转一圈对应两个相位周期，但是，我们在算法表示的时候又希望这两个相位周期都能得到数值上的一一对应，于是就出现了电角度=2机械角度；以此类推，当极对数为11时，机械角度的转一圈对应11个相位周期，因此，为了电角度能得到一一对应，就有了电角度=11机械角度。<strong>以此类推，我们就有了公式：电角度=机械角度x极对数</strong></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2023/05/27/%E7%81%AF%E5%93%A5%E6%95%99%E7%A8%8B%E4%B9%8B%E5%B8%95%E5%85%8B%E5%8F%98%E6%8D%A2/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2023/05/27/%E7%81%AF%E5%93%A5%E6%95%99%E7%A8%8B%E4%B9%8B%E5%B8%95%E5%85%8B%E5%8F%98%E6%8D%A2/" class="post-title-link" itemprop="url">灯哥教程之帕克变换</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-05-27 20:52:15" itemprop="dateCreated datePublished" datetime="2023-05-27T20:52:15+08:00">2023-05-27</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E7%94%B5%E6%9C%BA/" itemprop="url" rel="index"><span itemprop="name">电机</span></a>
                </span>
            </span>

          
            <span id="/2023/05/27/%E7%81%AF%E5%93%A5%E6%95%99%E7%A8%8B%E4%B9%8B%E5%B8%95%E5%85%8B%E5%8F%98%E6%8D%A2/" class="post-meta-item leancloud_visitors" data-flag-title="灯哥教程之帕克变换" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/05/27/%E7%81%AF%E5%93%A5%E6%95%99%E7%A8%8B%E4%B9%8B%E5%B8%95%E5%85%8B%E5%8F%98%E6%8D%A2/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/05/27/%E7%81%AF%E5%93%A5%E6%95%99%E7%A8%8B%E4%B9%8B%E5%B8%95%E5%85%8B%E5%8F%98%E6%8D%A2/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        原文链接：<a target="_blank" rel="noopener" href="https://www.bilibili.com/video/BV1t24y1u7do/?spm_id_from=pageDriver&amp;vd_source=2ef3411e1c045a25cc2351abaa2c3ce8">https://www.bilibili.com/video/BV1t24y1u7do/?spm_id_from=pageDriver&amp;vd_source=2ef3411e1c045a25cc2351abaa2c3ce8</a></p>
<p>​        <a target="_blank" rel="noopener" href="http://www.dengfoc.com/#/dengfoc/%E7%81%AF%E5%93%A5%E6%89%8B%E6%8A%8A%E6%89%8B%E6%95%99%E4%BD%A0%E5%86%99FOC%E7%AE%97%E6%B3%95/3.3%E5%B8%95%E5%85%8B%E5%8F%98%E6%8D%A2">http://www.dengfoc.com/#/dengfoc/%E7%81%AF%E5%93%A5%E6%89%8B%E6%8A%8A%E6%89%8B%E6%95%99%E4%BD%A0%E5%86%99FOC%E7%AE%97%E6%B3%95/3.3%E5%B8%95%E5%85%8B%E5%8F%98%E6%8D%A2</a></p>
<p>​        <img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305271621919.png" style="zoom:57%;"></p>
<p>​        由克拉克变换，实际上我们已经成功对电机的正弦驱动三相曲线进行降维度，使之变成了一个两轴坐标问题，并且得到其转换关系。但是只有它是不够的，我们还需要将这个理论和旋转电机对应起来，也就是<strong>建立电机旋转时的数学模型</strong>。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305271622420.png" style="zoom:80%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305271631282.png" style="zoom:80%;">

<p>​        答案是有！帕克变换就是想带我们做这件事！！</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305271839615.png" style="zoom:80%;">

<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305271854887.png"></p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305272024530.png" style="zoom:80%;">

<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305272026351.png"></p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305272035994.png"></p>
<h3 id="复盘FOC算法过程"><a href="#复盘FOC算法过程" class="headerlink" title="复盘FOC算法过程"></a>复盘FOC算法过程</h3><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305272044561.png" style="zoom:67%;">

<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305272050737.png"></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  


  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/page/7/"><i class="fa fa-angle-left" aria-label="上一页"></i></a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/7/">7</a><span class="page-number current">8</span><a class="page-number" href="/page/9/">9</a><span class="space">&hellip;</span><a class="page-number" href="/page/29/">29</a><a class="extend next" rel="next" href="/page/9/"><i class="fa fa-angle-right" aria-label="下一页"></i></a>
  </nav>



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">xudonglei</p>
  <div class="site-description" itemprop="description">搬砖 嵌入式</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">283</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">19</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">67</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2024</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">xudonglei</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://muse.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : false,
      appId      : 'BT0Qw9HcTpPv1a6cT1iDBXKz-gzGzoHsz',
      appKey     : 'LMCMh8v02JTMFAwKNRcgoizI',
      placeholder: "Just go go",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : true,
      lang       : 'zh-CN' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
